/**
 * Created by zhengjiachao on 2017/5/15.
 */

ADF.modalRenderer.BaseModalRenderer = function(){
    ADF.modalRenderer.BaseModalRenderer.superclass.constructor.call(this);
};

ADF.modalRenderer.BaseModalRenderer.ID = "baseModalRenderer";

COM.util.defineClass(ADF.modalRenderer.BaseModalRenderer, Object,{

    init : function(container){
        this.container = container;
        this.$modalDom = $(this.getModelHTML());
        this.contentContainer = this.$modalDom.find('.modal-body')[0];
        this.$modalDom.find('.adf-ok').click(function(){
            if(this.closeCallback){
                var canClose = this.closeCallback(this._getContentData(this.contentContainer));
                // if(canClose === false){
                //     return;
                // }
            }
            this.$modalDom.modal('hide');
        }.bind(this));
        $(this.container).append(this.$modalDom);
    },

    getModelHTML : function(){
        var domStr = '\
            <div class="modal" tabindex="-1" role="dialog">\
                <div class="modal-dialog modal-lg" role="document">\
                    <div class="modal-content">\
                    <div class="modal-header">\
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>\
                        <h4 class="modal-title" id="gridSystemModalLabel">' + this._getTitle() + '</h4>\
                    </div>\
                    <div class="modal-body">\
                    </div>\
                    <div class="modal-footer">\
                        <button type="button" class="btn btn-default" data-dismiss="modal">' + this._getCancelButtonText() + '</button>\
                        <button type="button" class="btn btn-primary adf-ok">' + this._getOkButtonText() + '</button>\
                    </div>\
                    </div>\
                </div>\
            </div>\
        ';
        return domStr;
    },

    _getOkButtonText : function(){
        return '保存';
    },

    _getCancelButtonText : function(){
        return '取消';
    },
    
    _getTitle : function(){
        return '默认标题';
    },

    show : function(contentData, callback){
       this._renderBody(this.contentContainer, contentData);
       this.closeCallback = callback;
       this.$modalDom.modal('show');
    },

    _renderBody : function(parentDom, contentData){
    },

    _getContentData : function(parentDom){
        return "";
    },

    getID : function(){
        return ADF.modalRenderer.BaseModalRenderer.ID;
    }
    
});